home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / CRYPT19.ZIP / PASSEXE.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-08-05  |  15.3 KB  |  492 lines

  1. ;─────────────────────────────────────────────────────────────────────────────
  2. ;                   Black Wolf's File Protection Utilities 2.1s
  3. ;
  4. ;PassEXE - This program password protects the specified file by attaching
  5. ;          code from PW_EXE onto the file so that it will check for passwords
  6. ;          each execution.  It utilizes ULTIMUTE .93ß to protect then PW_EXE
  7. ;          code from easy manipulation.
  8. ;
  9. ;LISCENSE:
  10. ;    Released As Freeware - These files may be distributed freely.
  11. ;
  12. ;Any modifications made to this program should be listed below the solid line,
  13. ;along with the name of the programmer and the date the file was changed.
  14. ;Also - they should be commented where changed.
  15. ;
  16. ;NOTE THAT MODIFICATION PRIVILEDGES APPLY ONLY TO THIS VERSION (2.1s)!  
  17. ;I'd appreciate notification of any modifications if at all possible, 
  18. ;reach me through the address listed in the documentation file (bwfpu21s.doc).
  19. ;
  20. ;DISCLAIMER:  The author takes ABSOLUTELY NO RESPONSIBILITY for any damages
  21. ;resulting from the use/misuse of this program/file.  The user agrees to hold
  22. ;the author harmless for any consequences that may occur directly or 
  23. ;indirectly from the use of this program by utilizing this program/file
  24. ;in any manner.
  25. ;─────────────────────────────────────────────────────────────────────────────
  26. ;Modifications:
  27. ;       None as of 08/05/93 - Initial Release.
  28.  
  29. .model tiny
  30. .radix 16
  31. .code
  32.        
  33.        org 100
  34.  
  35.         extrn   _ULTMUTE:near, _END_ULTMUTE:byte
  36.  
  37. start:
  38.         call    GetFilename
  39.         call    Get_Passes
  40.         call    EncryptGP       ;needs work here....
  41.         call    Do_File
  42.         mov     ax,4c00
  43.         int     21
  44. ;---------------------------------------------------------------------------
  45. GetFilename:
  46.         mov     ah,09
  47.         mov     dx,offset Message
  48.         int     21
  49.  
  50.         mov     dx,offset Filename_Data
  51.         mov     al,60
  52.         call    gets
  53.         ret
  54. ;---------------------------------------------------------------------------
  55. Get_Passes:
  56.     Clear_Out_Passes:        
  57.         mov     di,offset Entered_Pass
  58.         mov     cx,0ch                   ;Clear out entered pass.
  59.         xor     ax,ax
  60.         repnz   stosb
  61.         mov     di,offset Password
  62.         mov     cx,0ch                   ;Clear out entered pass.
  63.         xor     ax,ax
  64.         repnz   stosb
  65.         
  66.         mov     ah,09
  67.         mov     dx,offset Req_Pass
  68.         int     21
  69.  
  70.         mov     di,offset Entered_Pass
  71.         mov     cx,0ch
  72.         call    GetPass
  73.  
  74.         mov     ah,09
  75.         mov     dx, offset Dup_Pass
  76.         int     21
  77.  
  78.         mov     di,offset Password
  79.         mov     cx,0ch
  80.         call    GetPass
  81.         
  82.         call    Check_Passwords
  83.         jc      Get_Passes
  84.         
  85.         mov     di,offset Entered_Pass
  86.         mov     cx,0dh                   ;Clear out entered pass.
  87.         xor     ax,ax
  88.         repnz   stosb
  89.  
  90. Randomize_Keys:
  91.         push    ds
  92.         xor     ax,ax
  93.         mov     ds,ax
  94.         mov     ax,word ptr ds:[46c]    ;Randomizes encryption
  95.         pop     ds
  96.         mov     word ptr [Key1],ax
  97.         xor     ax,1f3eh
  98.         ror     ax,1
  99.         mov     word ptr [Key2],ax
  100.         
  101.  
  102.  
  103. Encrypt_Password:
  104.         mov     bx,word ptr [Key1]
  105.         mov     dx,word ptr [Key2]      ;Encrypt the password - needs 
  106.         mov     si,offset Password      ;some work on algorithm....
  107.         mov     di,si
  108.         mov     cx,6
  109.   EncryptIt:      
  110.         lodsw
  111.         xor     ax,bx
  112.         add     bx,dx
  113.         stosw
  114.         loop    EncryptIt
  115.         ret
  116. ;---------------------------------------------------------------------------
  117. Message:
  118.         db      'PassEXE 2.0 (c) 1993 Black Wolf Enterprises.',0a,0dh
  119.         db      'Enter Filename To Protect -> $'
  120. ;---------------------------------------------------------------------------
  121. Req_Pass        db      0a,0dh,'Now Enter Password (up to 12 chars): $'
  122. Dup_Pass        db      0a,0dh,'Re-Enter Password: $'
  123. Passes_Not      db      0a,0dh,'Passwords do not match.  Try again.',0a,0dh,24
  124. ;---------------------------------------------------------------------------
  125. Check_Passwords:
  126.         mov     si,offset Entered_Pass
  127.         mov     di,offset Password
  128.         mov     cx,0c
  129.         repz    cmpsb
  130.         jcxz    Password_Good
  131.         stc
  132.         ret
  133. Password_Good:
  134.         clc
  135.         ret
  136. ;---------------------------------------------------------------------------
  137.  
  138.  
  139. gets:
  140.         mov     ah,0a           ;Get string
  141.         push    bx
  142.         mov     bx,dx
  143.         mov     byte ptr ds:[bx],al
  144.         mov     byte ptr ds:[bx+1],0
  145.         pop     bx
  146.         int     21
  147.         push    bx
  148.         mov     bx,dx
  149.         mov     al,byte ptr ds:[bx+1]
  150.         xor     ah,ah
  151.         add     bx,ax
  152.         mov     byte ptr ds:[bx+2],0
  153.         pop     bx
  154.         ret
  155. ;---------------------------------------------------------------------------
  156. GetPass:
  157.   KeyHit_Loop:
  158.         push    cx
  159.         sub     ax,ax
  160.         int     16
  161.         cmp     al,0dh
  162.         je      HitReturn
  163.         stosb
  164.         pop     cx
  165.         loop    KeyHit_Loop
  166.         ret
  167.   HitReturn:
  168.         pop     cx
  169.         xor     al,al
  170.         repnz   stosb
  171.         ret        
  172.  
  173.  
  174. ;---------------------------------------------------------------------------
  175. Save_Header:                               ;Save important values from header
  176.         
  177.         mov     ax,word ptr [exeheader+0e]    ;Save old SS
  178.         mov     word ptr [Old_SS],ax
  179.         mov     ax,word ptr [exeheader+10]    ;Save old SP
  180.         mov     word ptr [Old_SP],ax
  181.         mov     ax,word ptr [exeheader+14]    ;Save old IP
  182.         mov     word ptr [Old_IP],ax
  183.         mov     ax,word ptr [exeheader+16]    ;Save old CS
  184.         mov     word ptr [Old_CS],ax
  185.         ret
  186.  
  187. GetTime:
  188.         mov     ax,5700
  189.         int     21
  190.         mov     word ptr cs:[Time],cx
  191.         mov     word ptr cs:[Date],dx
  192.         ret
  193. SetTime:
  194.         mov     ax,5701
  195.         mov     cx,word ptr cs:[Time]
  196.         mov     dx,word ptr cs:[Date]
  197.         int     21
  198.         ret
  199.  
  200.  
  201. Do_File:        
  202.         mov     ax,3d02
  203.         mov     dx,offset Filename
  204.         int     21                      ;open read/write
  205.         jc      Terminate
  206.         xchg    bx,ax
  207.         
  208.         call    GetTime        
  209.         call    BackupFile
  210.  
  211.         mov     ah,3f
  212.         mov     cx,1a
  213.         mov     dx,offset EXEheader     ;read in header info
  214.         int     21
  215.  
  216.         cmp     word ptr [EXEheader],'ZM'       ;not EXE file - don't 
  217.         jne     close_file                      ;protect it....
  218.         call    Save_Header
  219.         
  220.         mov     ax,4202
  221.         xor     cx,cx                   ;go to end of file
  222.         xor     dx,dx
  223.         int     21
  224.         
  225.         push    ax dx                   ;save file size
  226.  
  227.         call    calculate_CSIP          ;calculate starting
  228.                                         ;point.
  229.  
  230.         mov     ah,40
  231.         mov     dx,offset Set_Segs       ;write in the 'push es ds'
  232.         mov     cx,end_set_segs-set_segs ;'push cs cs' 'pop es ds' stuff...
  233.         int     21
  234.  
  235.         push    bx        
  236.         mov     si,offset begin_password        ;On Entry -> CS=DS=ES
  237.         mov     di,offset _END_ULTMUTE          ;SI=Source, DI=Destination
  238.         
  239.         mov     bx,word ptr [exeheader+14]       ;BX=Next Entry Point
  240.         add     bx,end_set_segs-set_segs
  241.  
  242.         mov     cx,end_password-begin_password+1 ;CX=Size to Encrypt
  243.         mov     ax,1                             ;AX=Calling Style
  244.         
  245.         call    _ULTMUTE                        ;Encrypt code
  246.                                                 
  247.                                                 ;On Return -> CX=New Size
  248.  
  249.         pop     bx
  250.         
  251.         pop     dx ax                   ;DX:AX = unmodified
  252.                                         ;file size.
  253.         
  254.         push    cx bx
  255.         add     cx,end_set_segs-set_segs
  256.         call    calculate_size
  257.         pop     bx cx
  258.  
  259.         mov     dx,offset _END_ULTMUTE
  260.         mov     ah,40                   ;Append host
  261.         int     21
  262.         
  263.         mov     ax,4200
  264.         xor     dx,dx
  265.         xor     cx,cx
  266.         int     21
  267.         
  268.         mov     ah,40
  269.         mov     cx,1a
  270.         mov     dx,offset EXEheader
  271.         int     21
  272.         
  273. Close_File:
  274.         call    SetTime
  275.         mov     ah,3e
  276.         int     21
  277.         ret
  278.  
  279. Terminate:
  280.         mov     ah,09
  281.         mov     dx,offset BadFile
  282.         int     21
  283.         ret
  284. BadFile db      'Error Opening File.',07,0dh,0a,24
  285.  
  286. calculate_CSIP:
  287.         push    ax
  288.         mov     cl,4 
  289.         mov     ax,word ptr [exeheader+8]       ;Get header length
  290.                                                 ;and convert it to
  291.         shl     ax,cl                           ;bytes.
  292.         mov     cx,ax
  293.         pop     ax
  294.  
  295.         sub     ax,cx                           ;Subtract header
  296.         sbb     dx,0                            ;size from file
  297.                                                 ;size for memory
  298.                                                 ;adjustments
  299.  
  300.         mov     cl,0c                           ;Convert DX into
  301.         shl     dx,cl                           ;segment Address
  302.         mov     cl,4
  303.         push    ax                      ;Change offset (AX) into
  304.         shr     ax,cl                   ;segment, except for last
  305.         add     dx,ax                   ;digit.  Add to DX and
  306.         shl     ax,cl                   ;save DX as new CS, put
  307.         pop     cx                      ;left over into CX and
  308.         sub     cx,ax                   ;store as the new IP.
  309.         mov     word ptr [exeheader+16],dx    ;Set new CS:IP
  310.         mov     word ptr [exeheader+10],0fffe ;Set new SP
  311.         mov     word ptr [exeheader+0e],dx    ;Set new SS = CS
  312.         mov     word ptr [exeheader+14],cx
  313.         ret
  314.  
  315. calculate_size:
  316.         push    ax                      ;Save offset for later
  317.         
  318.         add     ax,cx                   ;Add program size to DX:AX
  319.         
  320.         adc     dx,0
  321.  
  322.         mov     cl,7
  323.         shl     dx,cl                   ;convert DX to pages
  324.         mov     cl,9
  325.         shr     ax,cl
  326.         add     ax,dx
  327.         inc     ax
  328.         mov     word ptr [exeheader+04],ax  ;save # of pages
  329.  
  330.         pop     ax                              ;Get offset
  331.         mov     dx,ax
  332.         shr     ax,cl                           ;Calc remainder
  333.         shl     ax,cl                           ;in last page
  334.         sub     dx,ax
  335.         mov     word ptr [exeheader+02],dx ;save remainder
  336.         ret
  337.  
  338. EncryptGP:                              ;Encrypt GoodPass
  339.         xor     ax,ax
  340.         mov     cx,0c
  341.         mov     si,offset Password
  342.  
  343. GetValue:        
  344.         lodsb
  345.         add     ah,al
  346.         ror     ah,1                    ;Get value to use for encrypt...
  347.         loop    GetValue
  348.  
  349.         mov     si,offset Goodpass
  350.         mov     cx,EndGoodPass-GoodPass
  351.         
  352. Decrypt_Restore:        
  353.         mov     al,[si]
  354.         xor     al,ah
  355.         mov     [si],al
  356.         inc     si
  357.         loop    Decrypt_Restore
  358.         ret        
  359.  
  360. Time    dw      0
  361. Date    dw      0
  362.  
  363. Set_Segs:
  364.         push    es ds
  365.         push    cs cs
  366.         pop     es ds
  367.  End_Set_Segs:
  368.  
  369. BackupFile:                     ;Make backup of file...
  370.         mov     si,offset Filename
  371.         mov     cx,80
  372.  
  373.   Find_Eofn:                    ;Find end of file name...
  374.         lodsb
  375.         cmp     al,'.'
  376.         je      FoundDot
  377.         or      al,al
  378.         jz      FoundZero
  379.         loop    Find_Eofn
  380.         jmp     Terminate
  381. FoundZero:
  382.         mov     byte ptr [si-1],'.'
  383.         inc     si
  384. FoundDot:
  385.         mov     word ptr [si],'LO'
  386.         mov     byte ptr [si+2],'D'     ;Set filename to *.OLD
  387.         mov     byte ptr [si+3],0
  388.  
  389.         
  390.         mov     dx,offset Filename
  391.         mov     word ptr [SourceF],bx
  392.         mov     ah,3c
  393.         xor     cx,cx
  394.         int     21
  395.         jnc     GCreate
  396.          jmp    Terminate
  397. GCreate:
  398.         mov     word ptr cs:[Destf],ax
  399. BackLoop:
  400.         mov     ah,3f
  401.         mov     bx,word ptr cs:[Sourcef]
  402.         mov     cx,400
  403.         mov     dx,offset FileBuffer
  404.         int     21
  405.  
  406.         mov     cx,ax
  407.         mov     ah,40
  408.         mov     bx,word ptr cs:[Destf]
  409.         mov     dx,offset Filebuffer
  410.         int     21
  411.  
  412.         cmp     ax,400
  413.         je      BackLoop
  414. DoneBack:
  415.         call    SetTime
  416.  
  417.         mov     ah,3e
  418.         mov     bx,word ptr cs:[Destf]
  419.         int     21
  420.  
  421.         mov     ax,4200
  422.         xor     cx,cx
  423.         xor     dx,dx
  424.         mov     bx,word ptr cs:[Sourcef]
  425.         int     21
  426.         ret
  427.  
  428. SourceF dw      0
  429. DestF   dw      0
  430.  
  431.  
  432. begin_password:
  433. db 0e8h, 01fh, 01h, 0c6h, 086h, 08h, 01h, 0c3h, 0ebh, 01h
  434. db 090h, 0fah, 050h, 01eh, 033h, 0c0h, 08eh, 0d8h, 08dh, 086h
  435. db 0eh, 02h, 087h, 06h, 00h, 00h, 050h, 08ch, 0c8h, 087h
  436. db 06h, 02h, 00h, 050h, 01eh, 0eh, 01fh, 02eh, 0c7h, 086h
  437. db 02eh, 01h, 090h, 090h, 033h, 0c9h, 0f7h, 0f1h, 01fh, 058h
  438. db 087h, 06h, 02h, 00h, 058h, 087h, 06h, 00h, 00h, 01fh
  439. db 058h, 0fbh, 0e8h, 0b2h, 00h, 0e8h, 095h, 00h, 0e8h, 07fh
  440. db 00h, 072h, 050h, 033h, 0c0h, 0b9h, 0ch, 00h, 08dh, 0b6h
  441. db 044h, 02h, 0ach, 02h, 0e0h, 0d0h, 0cch, 0e2h, 0f9h, 08dh
  442. db 0b6h, 06fh, 01h, 0b9h, 029h, 00h, 08ah, 04h, 032h, 0c4h
  443. db 088h, 04h, 046h, 0e2h, 0f7h, 0e8h, 051h, 00h, 0ebh, 01h
  444. db 0ffh 
  445.  
  446. GoodPass:
  447. db 07h, 01fh, 08ch, 0c0h, 05h, 010h, 00h, 02eh, 01h
  448. db 086h, 032h, 02h, 02eh, 03h, 086h, 034h, 02h, 0fah, 08eh
  449. db 0d0h, 02eh, 08bh, 0a6h, 036h, 02h, 0fbh, 033h, 0c0h, 08bh
  450. db 0f0h, 08bh, 0f8h, 02eh, 0ffh, 0aeh, 030h, 02h, 090h, 090h
  451. db 090h, 090h, 0ffh 
  452. EndGoodPass:
  453.  
  454. db 0b4h, 09h, 08dh, 096h, 0a6h, 01h, 0cdh
  455. db 021h, 0b8h, 01h, 04ch, 0cdh, 021h, 0ah, 0dh, 050h, 061h
  456. db 073h, 073h, 077h, 06fh, 072h, 064h, 020h, 049h, 06eh, 063h
  457. db 06fh, 072h, 072h, 065h, 063h, 074h, 02eh, 07h, 024h, 090h
  458. db 0ebh, 03h, 090h, 0f8h, 0c3h, 0fch, 0ebh, 0fbh, 08dh, 0b6h
  459. db 044h, 02h, 08dh, 0beh, 038h, 02h, 0b9h, 0ch, 00h, 0f3h
  460. db 0a6h, 0e3h, 02h, 0f9h, 0c3h, 0f8h, 0c3h, 08bh, 09eh, 02ch
  461. db 02h, 08bh, 096h, 02eh, 02h, 08dh, 0b6h, 044h, 02h, 08bh
  462. db 0feh, 0b9h, 06h, 00h, 0adh, 033h, 0c3h, 03h, 0dah, 0abh
  463. db 0e2h, 0f8h, 0c3h, 0b9h, 0ch, 00h, 08dh, 0beh, 044h, 02h
  464. db 051h, 02bh, 0c0h, 0cdh, 016h, 03ch, 0dh, 074h, 05h, 0aah
  465. db 059h, 0e2h, 0f3h, 0c3h, 059h, 032h, 0c0h, 0f2h, 0aah, 0c3h
  466. db 0b4h, 09h, 08dh, 096h, 017h, 02h, 0cdh, 021h, 0cfh, 050h
  467. db 061h, 073h, 073h, 077h, 06fh, 072h, 064h, 02dh, 03eh, 024h
  468. db 05dh, 0ebh, 01h, 0eah, 055h, 081h, 0edh, 03h, 01h, 0c3h
  469. ;------------------------------------------------------------------------
  470. Key1            dw      0
  471. Key2            dw      0
  472. ;------------------------------------------------------------------------
  473. Old_IP  dw      0
  474. Old_CS  dw      0fff0
  475. Old_SS  dw      0fff0
  476. Old_SP  dw      0
  477. ;------------------------------------------------------------------------
  478. Password        db      'Greets progr'
  479. Entered_Pass    db      'ammers.. }-)'
  480. ;------------------------------------------------------------------------
  481. end_password:
  482.                 dw      0
  483.                 dw      0
  484. Filename_data   dw      0
  485. Filename        db      80 dup(0)
  486. FileBuffer      dw      400 dup(0)
  487. Exeheader       db      1a dup(0)
  488. end start
  489.  
  490.  
  491.  
  492.